var sqlUtils = require('../util/sqlUtil');
// 封装添加学校年级班级的方法
module.exports = {
  addMessage: function (grades, grade, classnum, insertId) {
    var gradenum = '';
    if (grade == "l1" || grade == "l4") {
      gradenum = 6;
    } else if (grade == "l2" || grade == "l3") {
      gradenum = 3;
    }
    for (var i = 0; i < gradenum; i++) {
      sql = "insert into grade (g_name,sid,is_del) value (?,?,0);"
      sqlArr = [grades[i], insertId];
      sqlUtils.sqlConnect(sql, sqlArr, function (err, val) {
        if (err) {
          console.log(err);
        } else {
          for (var j = 0; j < classnum; j++) {
            sql = "insert into class (c_name,gid,is_del) value (?,?,0)"
            sqlUtils.sqlConnect(sql, [j + 1 + "班", val.insertId], function (err) {
              if (err) {
                console.log(err);
              }
            })
          }
        }
      });
    }
  }
}